/*
 * Copyright (C), 2007-2018, 铭师堂教育科技有限公司
 * FileName: CmdbServiceImpl.java
 * Author:   zhaoyi
 * Date:     2018年7月13日 上午9:23:02
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.secsbrain.cloudconsole.remote.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.secsbrain.common.utils.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.secsbrain.cloudconsole.remote.CmdbRemoteService;
import com.secsbrain.cloudconsole.remote.DeployRemoteService;
import com.secsbrain.common.ErrorCodeEnum;
import com.secsbrain.common.ResponseVo;
import com.secsbrain.common.utils.DevOpsHttpUtils;
import com.secsbrain.deploy.client.iface.DeployService;
import com.secsbrain.deploy.client.iface.ModelService;
import com.secsbrain.deploy.client.model.BatchBuildParam;
import com.secsbrain.deploy.client.model.BatchBuildResult;
import com.secsbrain.deploy.client.model.BuildLog;
import com.secsbrain.deploy.client.model.BuildModelDto;
import com.secsbrain.deploy.client.model.BuildParam;
import com.secsbrain.deploy.client.model.BuildQuery;
import com.secsbrain.deploy.client.model.BuildRecord;
import com.secsbrain.deploy.client.model.DeployParam;
import com.secsbrain.deploy.client.model.HealthDto;
import com.secsbrain.deploy.client.model.JobNameBuildParam;

/**
 * DEPLOY相关服务
 *
 * @author zhaoyi
 */
@Service
public class DeployRemoteServiceImpl implements DeployRemoteService {
	
    private static final Logger logger = LoggerFactory.getLogger(DeployRemoteServiceImpl.class);
	
	public static final String ENV_FLAG="prod";
	
    @Value("${spring.profiles.active}")
	private String profilesActive;
    
    @Value("${api.gateway.url.deploy:}")
	private String deployGatwayUrl;
    
    @Value("${deploy.env:}")
	private String deployEnv;
    
    @Autowired
    ModelService modelService;
    
    @Autowired
    DeployService deployService;
    
    @Autowired
    CmdbRemoteService cmdbRemoteService;
    
    @Autowired
    private DevOpsHttpUtils httpUtils;
    
    /* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBuildModelByApp(java.lang.Long)
	 */
	@Override
	public ResponseVo<BuildModelDto> queryBuildModelByApp(Long appId) {
		return modelService.queryBuildModelByApp(appId);
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#createDeployJob(com.secsbrain.deploy.client.model.DeployParam)
	 */
	@Override
	public ResponseVo<?> createDeployJob(DeployParam deployParam) {
		if(!ENV_FLAG.equals(profilesActive)){
			//其他测试环境之间走内部服务调用
			return modelService.createDeployJob(deployParam);
		}
		//线上新建模型
		if(deployParam.isSwitchflow()&&!this.isOnline(deployParam.getSwitchEnvName())){
			//如果是在线下分组发布，则线上的参数置为false
			deployParam.setSwitchflow(false);
		}
		ResponseVo<?> responseVo=modelService.createDeployJob(deployParam);
		if(!responseVo.isSuccess()){
			return responseVo;
		}
		
		//线下新建模型
		String requestUrl=deployGatwayUrl+"/createDeployJob";
		if(deployParam.isSwitchflow()&&this.isOnline(deployParam.getSwitchEnvName())){
			//如果是在线上分组发布，则线下的参数置为false
			deployParam.setSwitchflow(false);
		}
		String result=httpUtils.postRequest(requestUrl, deployEnv, JSON.toJSONString(deployParam));
		if(result==null){
			return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("新建模型线上已成功，但线下网络请求失败。请联系管理员异常处理！");
		}
		ResponseVo<?> responseVoOffline=JSON.parseObject(result, ResponseVo.class);
		if(!responseVoOffline.isSuccess()){
			return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("新建模型线上已成功，但线下网络请求失败。请联系管理员异常处理！");
		}
		return responseVoOffline;
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#updateDeployJob(com.secsbrain.deploy.client.model.DeployParam)
	 */
	@Override
	public ResponseVo<?> updateDeployJob(DeployParam deployParam) {
		if(!ENV_FLAG.equals(profilesActive)){
			//其他测试环境之间走内部服务调用
			return modelService.updateDeployJob(deployParam);
		}
		
		//线上修改模型
		boolean flag=false;
		if(deployParam.isSwitchflow()&&!this.isOnline(deployParam.getSwitchEnvName())){
			//如果是在线下分组发布，则线上的参数置为false
			deployParam.setSwitchflow(false);
			flag=true;
		}
		ResponseVo<?> responseVo=modelService.updateDeployJob(deployParam);
		if(!responseVo.isSuccess()){
			return responseVo;
		}
		
		if(flag){
			//将之前为了参数调用设为false的值重新改回来
			deployParam.setSwitchflow(true);
		}
		
		//线下修改模型
		String requestUrl=deployGatwayUrl+"/updateDeployJob";
		if(deployParam.isSwitchflow()&&this.isOnline(deployParam.getSwitchEnvName())){
			//如果是在线上分组发布，则线下的参数置为false
			deployParam.setSwitchflow(false);
		}
		String result=httpUtils.putRequest(requestUrl, deployEnv, JSON.toJSONString(deployParam));
		if(result==null){
			return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("修改模型线上已成功，但线下网络请求失败。请联系管理员异常处理！");
		}
		ResponseVo<?> responseVoOffline=JSON.parseObject(result, ResponseVo.class);
		if(!responseVoOffline.isSuccess()){
			return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("修改模型线上已成功，但线下网络请求失败。请联系管理员异常处理！");
		}
		return responseVoOffline;
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#deleteDeployJob(com.secsbrain.deploy.client.model.DeployParam)
	 */
	@Override
	public ResponseVo<?> deleteDeployJob(DeployParam deployParam) {
		if(!ENV_FLAG.equals(profilesActive)){
			//其他测试环境之间走内部服务调用
			return modelService.deleteDeployJob(deployParam);
		}
		//线上删除模型
		ResponseVo<?> responseVo=modelService.deleteDeployJob(deployParam);
		if(!responseVo.isSuccess()){
			return responseVo;
		}
		
		//线下删除模型
		String requestUrl=deployGatwayUrl+"/deleteDeployJob";
		String result=httpUtils.deleteRequest(requestUrl, deployEnv, JSON.toJSONString(deployParam));
		if(result==null){
			logger.error("删除模型线上已成功，但线下网络请求失败。请联系管理员异常处理！");
			return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("删除模型线上已成功，但线下网络请求失败。请联系管理员异常处理！");
		}
		ResponseVo<?> responseVoOffline=JSON.parseObject(result, ResponseVo.class);
		if(!responseVoOffline.isSuccess()){
			logger.error("删除模型线上已成功，但线下返回"+responseVoOffline.getMsg()+"，请联系管理员异常处理！");
			return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("删除模型线上已成功，但线下返回"+responseVoOffline.getMsg()+"，请联系管理员异常处理！");
		}
		return responseVo;
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryAllBuildModel()
	 */
	@Override
	public ResponseVo<List<BuildModelDto>> queryAllBuildModel() {
		return modelService.queryAllBuildModel();
	}
	
	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBranchList(java.lang.String)
	 */
	@Override
	public ResponseVo<List<String>> queryBranchList(String gitUrl) {
		return modelService.queryBranchList(gitUrl);
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#buildPre(com.secsbrain.deploy.client.model.BuildParam)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<Long> buildPre(BuildParam buildParam) {
		if(StringUtils.isEmpty(buildParam.getEnvName())){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(buildParam.getEnvName())){
			//调用线下deploy服务
			String requestUrl=deployGatwayUrl+"/buildPre";
			String result=httpUtils.postRequest(requestUrl, deployEnv, JSON.toJSONString(buildParam));
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			ResponseVo<Long> responseVo=JSON.parseObject(result, ResponseVo.class);
			if(responseVo.getData()!=null){
				responseVo.setData(Long.parseLong(responseVo.getData()+""));
			}
			return responseVo;
		}else{
			return deployService.buildPre(buildParam);
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#build(com.secsbrain.deploy.client.model.BuildParam)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<Long> build(BuildParam buildParam) {
		if(StringUtils.isEmpty(buildParam.getEnvName())){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(buildParam.getEnvName())){
			//调用线下deploy服务
			String requestUrl=deployGatwayUrl+"/build";
			String result=httpUtils.postRequest(requestUrl, deployEnv, JSON.toJSONString(buildParam));
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			
			ResponseVo<Long> responseVo=JSON.parseObject(result, ResponseVo.class);
			if(responseVo.getData()!=null){
				responseVo.setData(Long.parseLong(responseVo.getData()+""));
			}
			return responseVo;
		}else{
			return deployService.build(buildParam);
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#buildBatch(com.secsbrain.deploy.client.model.BatchBuildParam)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<BatchBuildResult> buildBatch(BatchBuildParam batchBuildParam) {
		if(batchBuildParam.getBuildParams().length<=0){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("批量构建至少需要有一个构建参数");
		}
		if(StringUtils.isEmpty(batchBuildParam.getBuildParams()[0].getEnvName())){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(batchBuildParam.getBuildParams()[0].getEnvName())){
			//调用线下deploy服务
			String requestUrl=deployGatwayUrl+"/buildBatch";
			String result=httpUtils.postRequest(requestUrl, deployEnv, JSON.toJSONString(batchBuildParam));
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
			
			ResponseVo<BatchBuildResult> responseVo=new ResponseVo<BatchBuildResult>(null);
			BeanUtils.copyProperties(jsonVo, responseVo);
			if(jsonVo.getData()!=null){
				BatchBuildResult batchBuildResult=JSONObject.toJavaObject(jsonVo.getData(), BatchBuildResult.class);
				responseVo.setData(batchBuildResult);
			}
			return responseVo;
		}else{
			return deployService.buildBatch(batchBuildParam);
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#buildByJobName(com.secsbrain.deploy.client.model.JobNameBuildParam)
	 */
	@Override
	public ResponseVo<?> buildByJobName(JobNameBuildParam jobNameBuildParam) {
		//直接调用当前环境，及线下到线下，线上到线上
		return deployService.buildByJobName(jobNameBuildParam);
	}
	
	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#getBuildLog(java.lang.Long, java.lang.Long)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<BuildLog> getBuildLog(Long buildId, Long start,String envName) {
		if(StringUtils.isEmpty(envName)){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(envName)){
			String requestUrl=deployGatwayUrl+"/getBuildLog";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("buildId", buildId);
			params.put("start", start);
			String result=httpUtils.getRequest(requestUrl, deployEnv, params);
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
			
			ResponseVo<BuildLog> responseVo=new ResponseVo<BuildLog>(null);
			BeanUtils.copyProperties(jsonVo, responseVo);
			if(jsonVo.getData()!=null){
				BuildLog buildLog=JSONObject.toJavaObject(jsonVo.getData(), BuildLog.class);
				responseVo.setData(buildLog);
			}
			return responseVo;
		}else{
			return deployService.getBuildLog(buildId, start);
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBuildRecordByBuildId(java.lang.Long)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<BuildRecord> queryBuildRecordByBuildId(Long buildId,String envName) {
		if(StringUtils.isEmpty(envName)){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(envName)){
			String requestUrl=deployGatwayUrl+"/queryBuildRecordByBuildId";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("buildId", buildId);
			String result=httpUtils.getRequest(requestUrl, deployEnv, params);
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
			
			ResponseVo<BuildRecord> responseVo=new ResponseVo<>(null);
			BeanUtils.copyProperties(jsonVo, responseVo);
			if(jsonVo.getData()!=null){
				BuildRecord buildRecord=JSONObject.toJavaObject(jsonVo.getData(), BuildRecord.class);
				responseVo.setData(buildRecord);
			}
			return responseVo;
		}else{
			return deployService.queryBuildRecordByBuildId(buildId);
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBuildListByBatchId(java.lang.Long)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<List<BuildRecord>> queryBuildListByBatchId(Long batchId) {
		//线下专用
		String requestUrl=deployGatwayUrl+"/queryBuildListByBatchId";
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("batchId", batchId);
		String result=httpUtils.getRequest(requestUrl, deployEnv, params);
		ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
		
		ResponseVo<List<BuildRecord>> responseVo=new ResponseVo<>(null);
		BeanUtils.copyProperties(jsonVo, responseVo);
		if(jsonVo.getData()!=null){
			List<BuildRecord> buildRecordList=JSON.parseArray(JSON.toJSONString(jsonVo.getData()), BuildRecord.class);
			responseVo.setData(buildRecordList);
		}
		return responseVo;
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBuildListByAppId(java.lang.Long, java.lang.String, java.lang.Integer, java.lang.Integer)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<List<BuildRecord>> queryBuildListByAppId(Long appId, String envName, Integer page,
			Integer limit) {
		if(StringUtils.isEmpty(envName)){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(envName)){
			String requestUrl=deployGatwayUrl+"/queryBuildListByAppId";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("appId", appId);
			params.put("envName", envName);
			params.put("page", page);
			params.put("limit", limit);
			String result=httpUtils.getRequest(requestUrl, deployEnv, params);
			ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
			
			ResponseVo<List<BuildRecord>> responseVo=new ResponseVo<>(null);
			BeanUtils.copyProperties(jsonVo, responseVo);
			if(jsonVo.getData()!=null){
				List<BuildRecord> buildRecordList=JSON.parseArray(JSON.toJSONString(jsonVo.getData()), BuildRecord.class);
				responseVo.setData(buildRecordList);
			}
			return responseVo;
		}else{
			return deployService.queryBuildListByAppId(appId, envName, page, limit);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBuildList(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, com.secsbrain.deploy.client.model.BuildQuery)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<List<BuildRecord>> queryAllBuildList(Integer page, Integer limit, String sortBy, String descending,
			BuildQuery buildQuery) {
		if(StringUtils.isEmpty(buildQuery.getEnvFlag())){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境标识不能为空");
		}
		if("offline".equals(buildQuery.getEnvFlag())){
			String requestUrl=deployGatwayUrl+"/queryAllBuildList";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("page", page);
			params.put("limit", limit);
			params.put("sortBy", sortBy);
			params.put("descending", descending);
			
			params.put("appName", buildQuery.getAppName());
			params.put("envName", buildQuery.getEnvName());
			params.put("branchName", buildQuery.getBranchName());
			params.put("startDate", buildQuery.getStartDate());
			params.put("endDate", buildQuery.getEndDate());
			params.put("status", buildQuery.getStatus());
			params.put("createName", buildQuery.getCreateName());

			String result=httpUtils.getRequest(requestUrl, deployEnv, params);
			ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
			
			ResponseVo<List<BuildRecord>> responseVo=new ResponseVo<>(null);
			BeanUtils.copyProperties(jsonVo, responseVo);
			if(jsonVo.getData()!=null){
				List<BuildRecord> buildRecordList=JSON.parseArray(JSON.toJSONString(jsonVo.getData()), BuildRecord.class);
				responseVo.setData(buildRecordList);
			}
			return responseVo;
		}else{
			return deployService.queryAllBuildList(page, limit, sortBy, descending, 
					buildQuery.getAppName(), buildQuery.getEnvName(), buildQuery.getBranchName(), 
					buildQuery.getStartDate(), buildQuery.getEndDate(), buildQuery.getStatus(), buildQuery.getCreateName());
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#queryBuildListByGroupId(java.lang.Long, java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseVo<List<BuildRecord>> queryBuildListByGroupId(Long groupId, String envName) {
		if(StringUtils.isEmpty(envName)){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(envName)){
			String requestUrl=deployGatwayUrl+"/queryBuildListByGroupId";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("groupId", groupId);
			params.put("envName", envName);
			String result=httpUtils.getRequest(requestUrl, deployEnv, params);
			ResponseVo<JSONObject> jsonVo=JSON.parseObject(result, ResponseVo.class);
			
			ResponseVo<List<BuildRecord>> responseVo=new ResponseVo<>(null);
			BeanUtils.copyProperties(jsonVo, responseVo);
			if(jsonVo.getData()!=null){
				List<BuildRecord> buildRecordList=JSON.parseArray(JSON.toJSONString(jsonVo.getData()), BuildRecord.class);
				responseVo.setData(buildRecordList);
			}
			return responseVo;
		}else{
			return deployService.queryBuildListByGroupId(groupId, envName);
		}
	}

	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#percentRelease(java.lang.Long, java.lang.Integer)
	 */
	@Override
	public ResponseVo<Integer> percentRelease(Long groupId, Integer percent) {
		//切流只考虑线上，直接服务内部调用
		return deployService.percentRelease(groupId, percent);
	}
	
	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#healthCheck(com.secsbrain.deploy.client.model.HealthDto, java.lang.String)
	 */
	@Override
	public ResponseVo<?> healthCheck(HealthDto healthDto, String envName) {
		if(StringUtils.isEmpty(envName)){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(envName)){
			String requestUrl=deployGatwayUrl+"/healthCheck";
			String result=httpUtils.postRequest(requestUrl, deployEnv, JSON.toJSONString(healthDto));
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			ResponseVo<?> responseVo=JSON.parseObject(result, ResponseVo.class);
			return responseVo;
		}else{
			return deployService.healthCheck(healthDto);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.secsbrain.development.remote.DeployRemoteService#serverUp(java.lang.Long, java.lang.String, java.lang.String)
	 */
	@Override
	public ResponseVo<?> serverUp(Long appId, String host,String envName) {
		if(StringUtils.isEmpty(envName)){
			return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo("环境名不能为空");
		}
		if(!this.isOnline(envName)){
			String requestUrl=deployGatwayUrl+"/serverUp";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("appId", appId);
			params.put("host", host);
			String result=httpUtils.getRequest(requestUrl, deployEnv, params);
			if(result==null){
				return ErrorCodeEnum.ERROR_COMMON_NETWORK_ERROR.getResponseVo("网络请求失败");
			}
			ResponseVo<?> responseVo=JSON.parseObject(result, ResponseVo.class);
			return responseVo;
		}else{
			return deployService.serverUp(appId, host);
		}
	}
	
	private boolean isOnline(String envName){
		String prex="online_";
		boolean exists= RedisUtil.kExists(prex+envName);
		if(exists){
			return "online".equals(RedisUtil.get(prex+envName));
		}
		ResponseVo<String> envFlagVo=cmdbRemoteService.queryEnvFlag(envName);
		if(envFlagVo.isSuccess()){
			RedisUtil.put(prex+envName, envFlagVo.getData(), 60*60*12);//缓存12个小时
			return "online".equals(envFlagVo.getData());
		}
		throw new RuntimeException("区分环境失败："+envFlagVo.getMsg());
	}

}
